package com.summer.algorithm;

//算法的起源
public class OriginAlgorithm {
	
	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		System.out.println("sum = " + String.valueOf(sum(1000000000)));
		System.out.println(System.currentTimeMillis() - time);
		

		long time1 = System.currentTimeMillis();
		System.out.println("sumAlgorithm = " + String.valueOf(sumAlgorithm(1000000000)));
		System.out.println(System.currentTimeMillis() - time1);
	}

	public static long sum(long endNumber){
		long sum = 0;
		for(int i=1;i<=endNumber;i++){
			sum += i;
		}
		return sum;
	}
	//高斯算法，等差数列。
	public static long sumAlgorithm(long endNumber){
		long sum = (1+endNumber)*(endNumber/2);
		return sum;
	}
	
}
